﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace tdgame
{
    class QuadRenderer
    {
        private GraphicsDevice device;
        private VertexPositionTexture[] vertices;
        private int[] indices;

        public QuadRenderer(Game game)
        {
            this.device = game.GraphicsDevice;
            this.vertices = new VertexPositionTexture[]
            {
                new VertexPositionTexture(
                    new Vector3(-1, 1, 0),
                    new Vector2(0, 0)),
                new VertexPositionTexture(
                    new Vector3(1, 1, 0),
                    new Vector2(1, 0)),
                new VertexPositionTexture(
                    new Vector3(-1, -1, 0),
                    new Vector2(0, 1)),
                new VertexPositionTexture(
                    new Vector3(1, 1, 0),
                    new Vector2(1, 1))
            };

            this.indices = new int[]
            {
                0, 1, 2,
                1, 3, 2
            };

        }

        public void Draw(ref Vector2 min, ref Vector2 max)
        {
            this.vertices[0].Position.X = min.X;
            this.vertices[0].Position.Y = max.Y;

            this.vertices[1].Position.X = max.X;
            this.vertices[1].Position.Y = max.Y;

            this.vertices[2].Position.X = min.X;
            this.vertices[2].Position.Y = min.Y;

            this.vertices[3].Position.X = max.X;
            this.vertices[3].Position.Y = min.Y;

            this.device.DrawUserIndexedPrimitives<VertexPositionTexture>(
                PrimitiveType.TriangleList,
                this.vertices,
                0,
                this.vertices.Length,
                this.indices,
                0,
                2);
        }

    }
}